(function () {
  var dpr = window.devicePixelRatio;
  var viewport = document.getElementById('viewport');
  var htmls = document.getElementsByTagName('html')[0];
  var content = null;
  window.onpageshow = function (event) {
      if (event.persisted) {
          window.location.reload();
      }
  };

  // 判断一下 参数中是否有scale参数，有的话就不缩放了
  var scale = window.location.search;
  if (scale && scale.indexOf('scale') > -1) {
      return;
  }
  var ratio = 1 / dpr;
  content = 'width=device-width, initial-scale=' + ratio + ', user-scalable=no, minimum-scale=' + ratio + ', maximum-scale=' + ratio;
  // 对于嵌入的iframe，在嵌入的登录框页面会存在缩放问题，暂时先不管3这种情况
  // else if (+dpr === 3) {
  //     var content = 'width=device-width, initial-scale=0.5, user-scalable=no, minimum-scale=0.3333333333, maximum-scale=0.333333333333';
  //     htmls.setAttribute('style', 'font-size: 48px');
  // }
  function updateFontSize() {
      var bWidth = document.documentElement.getBoundingClientRect().width;
      var bRate = 23.4375; // 根据iphone6标准算出来的
      var fontSize = bWidth / bRate;
      htmls.setAttribute('style', 'font-size: ' + fontSize + 'px');
  }
  window.addEventListener('resize', function () {
      updateFontSize();
  });
  // window.addEventListener('pageshow', function (b) {
  //     updateFontSize();
  // });
  if (content) {
      viewport.setAttribute('content', content);
      viewport.setAttribute('ratio', ratio);
  }
  updateFontSize();
})();